package org.liziyi.pss.gui;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;

public class ProcessCreateDialogGUI extends JDialog {
    public JPanel contentPane;
    public JButton okJButton;
    public JButton cancelJButton;
    public JTable processJTable;

    public ProcessCreateDialogGUI(JFrame owner,String title) {
        super(owner,title);
        setContentPane(contentPane);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    }
    private void createUIComponents() {
        processJTable = new JTable(new DefaultTableModel(new Object[]{"PID", "时间片", "优先权", "内存", "状态", "属性"}, 0));
        DefaultTableCellRenderer defaultTableCellRenderer = new DefaultTableCellRenderer(){
            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                c.setBackground(Color.WHITE);
                if(value.toString().startsWith("同步")){
                    c.setForeground(Color.blue);
                } else{
                    c.setForeground(Color.black);
                }
                return c;
            }
        };
        defaultTableCellRenderer.setHorizontalAlignment(SwingConstants.CENTER);
        processJTable.setDefaultRenderer(Object.class,defaultTableCellRenderer);
        processJTable.getColumnModel().getColumn(5).setPreferredWidth((int) (processJTable.getPreferredSize().width * 0.3));
    }

    public JButton getOkJButton() {
        return okJButton;
    }

    public JButton getCancelJButton() {
        return cancelJButton;
    }

    public JTable getProcessJTable() {
        return processJTable;
    }
}
